package uitls;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author yangtao
 * @since 2021-07-21 9:12
 */
public class DBManager {

    //    静态常量  无法改变的量
    private static final String URL = "jdbc:mysql://127.0.0.1:3306/hk?serverTimezone=GMT&useSSL=false";
    private static final String USER = "root";
    private static final String PASSWORD = "root";


    //    程序只运行一次 静态代码块
    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }


    public static Connection getConn(){
        try {
            Connection connection = DriverManager.getConnection(URL, USER, PASSWORD);
            return connection;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }


    public static void main(String[] args) {

        Connection conn = DBManager.getConn();
        System.out.println(conn);

    }



}
